{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "occupational-circulation",
   "metadata": {},
   "source": [
    "# Problem 14.09 Temperature Change Upon Ethylene Expansion in Throttle Valves Using a High Precision EOS"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efficient-dress",
   "metadata": {},
   "source": [
    "Ethylene is expanded from P1 = 3000 bar, T1 = 600 K to P2 = 300 bar by a first valve, and then to P3 = 1 bar by a second valve. What are the temperatures T2 and T3? Neglect the velocity term in the solution."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "improved-holder",
   "metadata": {},
   "source": [
    "## Solution\n",
    "\n",
    "This is straightforward - an initial PT flash calculation, followed by two separate PH flash calculations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ignored-charles",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set the conditions and imports\n",
    "from scipy.constants import bar, hour\n",
    "from thermo import ChemicalConstantsPackage, PRMIX, CEOSLiquid, CoolPropLiquid, CEOSGas, CoolPropGas, FlashPureVLS\n",
    "fluid = 'ethylene'\n",
    "constants, correlations = ChemicalConstantsPackage.from_IDs([fluid])\n",
    "\n",
    "T1 = 600\n",
    "P1 = 3000*bar\n",
    "P2 = 300*bar\n",
    "P3 = 1*bar\n",
    "zs = [1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "interim-module",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The second temperature is  676.94 K\n",
      "The third temperature is  651.47 K\n"
     ]
    }
   ],
   "source": [
    "backend = 'HEOS'\n",
    "gas = CoolPropGas(backend, fluid, T=T1, P=P1, zs=zs)\n",
    "liquid = CoolPropLiquid(backend, fluid, T=T1, P=P1, zs=zs)\n",
    "\n",
    "flasher = FlashPureVLS(constants, correlations, gas=gas, liquids=[liquid], solids=[])\n",
    "\n",
    "# Flash at inlet conditions to obtain initial enthalpy\n",
    "state_1 = flasher.flash(T=T1, P=P1)\n",
    "state_2 = flasher.flash(H=state_1.H(), P=P2)\n",
    "state_3 = flasher.flash(H=state_1.H(), P=P3)\n",
    "\n",
    "print(f'The second temperature is {state_2.T: .2f} K')\n",
    "print(f'The third temperature is {state_3.T: .2f} K')"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
